function [S e g phiCoords w] = s_step(g, S, phiCoords, w)
global g_N;
global g_L;

e = random('bino', ones(g_N, S), g);
NumZ = sum(e);
DeltaNumS = 0;
g_new = [];
phiCoords_new = [];
w_new = [];

for s = 1:S
    if (NumZ(s) < g_L)
        DeltaNumS = DeltaNumS + 1;
    else
        g_new = cat(2, g_new, g(:, s));
        phiCoords_new = cat(1, phiCoords_new, phiCoords(s, :));
        w_new = cat(1, w_new, w(s));
    end
end

for n = 1:g_N
    g_new(n, :) = g_new(n, :) / sum(g_new(n, :));
end

w_new = w_new / sum(w_new);

S = S - DeltaNumS;
g = g_new;
w = w_new;
phiCoords = phiCoords_new;
e = random('bino', ones(g_N, S), g_new);

end